/*
 * @Author: humengchuan 531537052@qq.com
 * @Date: 2024-12-26 09:35:50
 * @LastEditors: humengchuan 531537052@qq.com
 * @LastEditTime: 2024-12-26 09:40:29
 * @FilePath: \projecte:\学习\react\react-optimize-ts\src\utils\useApi.ts
 * @Description: 
 */
// src/api/userApi.ts

import baseApi from './baseApi';

interface User {
  id: string;
  name: string;
  email: string;
  // 根据实际情况添加其他字段
}

const getUser = async (userId: string): Promise<User | null> => {
  return baseApi(`/users/${userId}`) as Promise<User | null>;
};

const createUser = async (userData: User): Promise<User> => {
  return baseApi('/users', {
    method: 'POST',
    // headers: {
    //   'Content-Type': 'application/json',
    // },
    body: JSON.stringify(userData),
  }) as Promise<User>;
};

const updateUser = async (userId: string, userData: Partial<User>): Promise<User> => {
  return baseApi(`/users/${userId}`, {
    method: 'PUT',
    body: JSON.stringify(userData),
  }) as Promise<User>;
};

const deleteUser = async (userId: string): Promise<void> => {
  return baseApi(`/users/${userId}`, {
    method: 'DELETE',
  }) as Promise<void>;
};

export { getUser, createUser, updateUser, deleteUser };